package com.example.user.myzzyl_android;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.smssdk.EventHandler;
import cn.smssdk.SMSSDK;
import cn.smssdk.gui.RegisterPage;

public class UserActivity extends Activity {
    public String TAG = "UserActivity";
    @BindView(R.id.btn_showSideMenu)
    ImageButton btnShowSideMenu;
    @BindView(R.id.show_QR)
    ImageButton showQR;
    @BindView(R.id.SimpleDraweeView2)
    SimpleDraweeView SimpleDraweeView2;
    @BindView(R.id.tv_username)
    TextView tvUsername;
    UserAdpter userAdpter;
    Unbinder unbinder;
    @BindView(R.id.list_item)
    ListView listview;
    List<String> list = new ArrayList<>();

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        ButterKnife.bind(this);
        list.add("我的足迹");
        list.add("退出登录");
        userAdpter = new UserAdpter(this, list);
        listview.setAdapter(userAdpter);
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(UserActivity.this, "此功能需要登录", Toast.LENGTH_SHORT).show();
            }
        });

    }

    @OnClick(R.id.SimpleDraweeView2)
    public void onViewClicked() {
        final RegisterPage registerPage = new RegisterPage();
        registerPage.setRegisterCallback(new EventHandler() {
            @Override
            public void afterEvent(final int i, int i1, Object o) {
                if (i1 == SMSSDK.RESULT_COMPLETE) {
                    Log.i("ssssssxzsss", "6666666666666666666");
                    HashMap<String, Object> phoneMap = (HashMap<String, Object>) o;
                    String phone = (String) phoneMap.get("phone");
                    OkGo.<String>post("http://zhihui.expo2017.net.cn/zzwhe/resources/grzxHy/login")
                            .tag(this)
                            .params("phone", phone)
                            .execute(new StringCallback() {
                                @Override
                                public void onSuccess(Response<String> response) {
                                    Log.i("ssssssxzsss", response.body());
                                }
                            });
                }
            }
        });
        registerPage.show(getBaseContext());
    }

    @OnClick(R.id.btn_showSideMenu)
    public void onViewClicked2() {
        finish();
    }
}
